package com.softer.wxzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.enums.NumStrEnum;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.entity.DongleInfo;
import com.softer.wxzj.mapper.DongleInfoMapper;
import com.softer.wxzj.service.DongleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * DongleInfoServiceImpl
 *
 * @author wxr
 * 20190513
 */
@Service
public class DongleInfoServiceImpl implements DongleInfoService {
    @Autowired
    private DongleInfoMapper dongleInfoMapper;

    /**
     * 增加去掉
     *
     * @param dongleInfo
     * @return
     */
    @Override
    public CommonResult insert(DongleInfo dongleInfo) {
        return null;
    }

    /**
     * 增加加密狗
     *
     * @param operId
     * @return
     */
    @Override
    public CommonResult insertDongleInfo(String operId, String keyCode) {
        DongleInfo dongleInfo = new DongleInfo();
        //创建人
        dongleInfo.setCreater(ShiroUserUtil.getUserName());
        //开启状态
        dongleInfo.setOperId(operId);
        dongleInfo.setState(NumStrEnum.ONE.getNum());
        //加密狗id
        //TODO
        dongleInfo.setKeyCode(keyCode);
        int num = dongleInfoMapper.insert(dongleInfo);
        return CommonResult.ResponseResult(num);
    }

    @Override
    public List<DongleInfo> findDongleInfoList(DongleInfo dongleInfo) {
        return dongleInfoMapper.findDongleInfoList(dongleInfo);
    }

    @Override
    public CommonResult update(DongleInfo dongleInfo) {
        int num = dongleInfoMapper.update(dongleInfo);
        return CommonResult.ResponseResult(num);
    }

    @Override
    public CommonResult delete(String id) {
        int num = dongleInfoMapper.delete(id);
        return CommonResult.ResponseResult(num);
    }

    @Override
    public PageInfo<DongleInfo> getList(Page page, DongleInfo dongleInfo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<DongleInfo> list = dongleInfoMapper.getList(dongleInfo);
        PageInfo<DongleInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public DongleInfo getInfo(String id) {
        return null;
    }
}

